package com.test.nnooolwdeaer.dialog_wooden;

import android.annotation.SuppressLint;
import android.app.Dialog;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.widget.Button;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.test.nnooolwdeaer.R;
import com.test.nnooolwdeaer.activity_fragment_wooden.base_wooden.BaseActivity_wooden;

public class AppUpdateDialog_wooden extends Dialog {

    private BaseActivity_wooden activity_wooden;

    private final String updateUri_wooden;

    public AppUpdateDialog_wooden(@NonNull BaseActivity_wooden activity, String updateUri) {
        super(activity);
        this.activity_wooden = activity;
        this.updateUri_wooden = updateUri;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_app_update_wooden);
        initView_wooden();
    }

    @SuppressLint({"SetTextI18n", "ResourceAsColor"})
    private void initView_wooden(){

        getWindow().setBackgroundDrawableResource(R.color.trans);

        ((TextView)findViewById(R.id.dialog_app_update_tv_title)).setText("App Update");
        ((TextView)findViewById(R.id.dialog_app_update_tv_text)).setText("New version found, need to update now?");

        Button cancelBtn = findViewById(R.id.dialog_app_update_btn_cancel);
        Button updateBtn = findViewById(R.id.dialog_app_update_btn_submit);
        cancelBtn.setText("Cancel");
        updateBtn.setText("Update");
        cancelBtn.setTextColor(getContext().getColor(R.color.gray_dd));
        updateBtn.setTextColor(getContext().getColor(R.color.black));
        //拒绝更新:App结束运行
        cancelBtn.setOnClickListener(view -> {
            dismiss();
            activity_wooden.finish();
            activity_wooden = null;
        });
        //同意更新:跳转到网页更新
        updateBtn.setOnClickListener(view -> getContext().startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(updateUri_wooden))));

        setCanceledOnTouchOutside(false);
    }

}
